package com._51doit.day01.adv;

import com._51doit.day02.Function1;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class MyAdvListDemo {

    public static void main(String[] args) {

        MyAdvList<Double> lst = new MyAdvList<>();
        lst.add(1.0);
        lst.add(2.0);
        lst.add(3.0);
        lst.add(4.0);
        lst.add(5.0);

        List<Double> nList = lst.filter(b -> b > 3.0);

        for (Double r : nList) {
            System.out.println(r);
        }
        System.out.println(lst.map(i -> i * 10));
//        System.out.println(lst.reduce((a, b) -> a > b ? a : b));
//        System.out.println(lst.reduce((a, b) -> a + b ));
        MyAdvList<String> list = new MyAdvList<>();
        list.add("scala,hive,hadoop,hbase");
        list.add("hive,scala,hive,hbase");
        list.add("hbase,flink");
        list.add("hadoop");
        System.out.println(list.reduce((a, b) -> a + b));

        MyAdvList<String> lines = new MyAdvList<>();
        lines.add("scala,hive,hadoop,hbase");
        lines.add("hive,scala,hive,hbase");
        lines.add("hbase,flink");
        lines.add("hadoop");
        MyAdvList<String> words = lines.flatMap(new Function1<String, Iterator<String>>() {
            @Override
            public Iterator<String> invote(String s) {
                return Arrays.asList(s.split(",")).iterator();
            }
        }) ;
        System.out.println(words);

    }
}
